package com.zzyl.controller;

import com.zzyl.base.PageResponse;
import com.zzyl.base.ResponseResult;
import com.zzyl.dto.UserDto;
import com.zzyl.entity.User;
import com.zzyl.service.UserService;
import com.zzyl.vo.UserVo;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.apache.ibatis.annotations.Param;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/user")
@Api(tags = "用户管理模块相关接口")
public class UserController {
    @Autowired
    private UserService userService;

    @PostMapping("/page/{pageNum}/{pageSize}")
    @ApiOperation("分页查询")
    public ResponseResult<PageResponse<UserVo>> selectByPage(
            @RequestBody UserDto userDto,
            @PathVariable Integer pageNum,
            @PathVariable Integer pageSize){
        PageResponse<UserVo> page = userService.selectByPage(userDto,pageNum,pageSize);
        return ResponseResult.success(page);
    }

    @PutMapping
    @ApiOperation("用户添加")
    public ResponseResult add(@RequestBody UserDto userDto){
        userService.add(userDto);
        return ResponseResult.success();
    }

    @PutMapping("/is-enable/{id}/{status}")
    @ApiOperation("启用禁用")
    public ResponseResult enable(@PathVariable Long id,@PathVariable String status){
        userService.enable(id,status);
        return ResponseResult.success();
    }

    @PatchMapping
    @ApiOperation("编辑")
    public ResponseResult update(@RequestBody UserDto userDto){
        userService.update(userDto);
        return ResponseResult.success();
    }

    @DeleteMapping("/remove/{userId}")
    @ApiOperation("删除")
    public ResponseResult delete(@PathVariable Long userId){
        userService.delete(userId);
        return ResponseResult.success();
    }

    @PostMapping("/list")
    @ApiOperation("用户列表")
    public ResponseResult list(@RequestBody UserDto userDto){
        List<UserVo> userVos = userService.list(userDto);
        return ResponseResult.success(userVos);
    }

    @PostMapping("/reset-passwords/{userId}")
    @ApiOperation("重置密码")
    public ResponseResult resetPassWords(@PathVariable Long userId){
        userService.resetPassWords(userId);
        return ResponseResult.success();
    }


}
